home *** CD-ROM | disk | FTP | other *** search
- /* GNUPLOT - nextfe.trm */
-
- /* $Id: nextfe.trm,v 1.2 1993/03/18 04:44:47 davis Exp $ */
-
- /*
- * Copyright (C) 1990, 1992
- *
- * Permission to use, copy, and distribute this software and its
- * documentation for any purpose with or without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation.
- *
- * Permission to modify the software is granted, but not the right to
- * distribute the modified code. Modifications are to be distributed
- * as patches to released version.
- *
- * This software is provided "as is" without express or implied warranty.
- *
- * This file is included by ../term.c.
- *
- * This terminal driver supports:
- * postscript
- *
- * AUTHORS
- * Russell Lang (modified for the NeXTSTEP Front End by Robert Davis)
- *
- * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
- *
- * The 'postscript' driver produces landscape output 10" wide and 7" high.
- * To change font to Times-Roman and font size to 20pts use
- * 'set term postscript "Times-Roman" 20'.
- * To get a smaller (5" x 3.5") eps output use 'set term post eps'
- * and make only one plot per file. Font size for eps will be half
- * the specified size.
- */
-
-
- /* PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
- /* Modified by Robert Davis, davis@ecn.purdue.edu, 71302,273@compuserve.com */
-
- #import <streams/streams.h>
-
- NXStream *EPSStream;
- TBOOLEAN nextfe_needsReset;
-
- /*
- * The postscript driver by Russell Lang automatically halves the size
- * of EPS plots, as if you had done a "set size .5,.5". This is
- * handy, since most EPS plots don't need to be page-sized, but it may
- * come as a suprise for folks not expecting it. To turn it off, set
- * nextfe_halve to FALSE.
- */
- TBOOLEAN nextfe_halve = TRUE;
-
- char nextfe_font[MAX_ID_LEN+1] = "Helvetica" ; /* name of font */
- int nextfe_fontsize = 14; /* size of font in pts */
- TBOOLEAN nextfe_color = FALSE;
-
- int nextfe_path_count=0; /* count of lines in path */
- int nextfe_ang=0; /* text angle */
- enum JUSTIFY nextfe_justify=LEFT; /* text is flush left */
-
- char *NEXTFE_header[] = {
- "/M {moveto} bind def\n",
- "/L {lineto} bind def\n",
- "/R {rmoveto} bind def\n",
- "/V {rlineto} bind def\n",
- "/vpt2 vpt 2 mul def\n",
- "/hpt2 hpt 2 mul def\n",
- /* flush left show */
- "/Lshow { currentpoint stroke M\n",
- " 0 vshift R show } def\n",
- /* flush right show */
- "/Rshow { currentpoint stroke M\n",
- " dup stringwidth pop neg vshift R show } def\n",
- /* centred show */
- "/Cshow { currentpoint stroke M\n",
- " dup stringwidth pop -2 div vshift R show } def\n",
- /* Dash or Color Line */
- "/DL { Color {setrgbcolor [] 0 setdash pop}\n",
- " {pop pop pop 0 setdash} ifelse } def\n",
- /* Border Lines */
- "/BL { stroke gnulinewidth 2 mul setlinewidth } def\n",
- /* Axes Lines */
- "/AL { stroke gnulinewidth 2 div setlinewidth } def\n",
- /* Plot Lines */
- "/PL { stroke gnulinewidth setlinewidth } def\n",
- /* Line Types */
- "/LTb { BL [] 0 0 0 DL } def\n", /* border */
- "/LTa { AL [1 dl 2 dl] 0 setdash 0 0 0 setrgbcolor } def\n", /* axes */
- "/LT0 { PL [] 0 1 0 DL } def\n",
- "/LT1 { PL [4 dl 2 dl] 0 0 1 DL } def\n",
- "/LT2 { PL [2 dl 3 dl] 1 0 0 DL } def\n",
- "/LT3 { PL [1 dl 1.5 dl] 1 0 1 DL } def\n",
- "/LT4 { PL [5 dl 2 dl 1 dl 2 dl] 0 1 1 DL } def\n",
- "/LT5 { PL [4 dl 3 dl 1 dl 3 dl] 1 1 0 DL } def\n",
- "/LT6 { PL [2 dl 2 dl 2 dl 4 dl] 0 0 0 DL } def\n",
- "/LT7 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.3 0 DL } def\n",
- "/LT8 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 0.5 0.5 0.5 DL } def\n",
- "/P { stroke [] 0 setdash\n", /* Point */
- " currentlinewidth 2 div sub M\n",
- " 0 currentlinewidth V stroke } def\n",
- "/D { stroke [] 0 setdash 2 copy vpt add M\n", /* Diamond */
- " hpt neg vpt neg V hpt vpt neg V\n",
- " hpt vpt V hpt neg vpt V closepath stroke\n",
- " P } def\n",
- "/A { stroke [] 0 setdash vpt sub M 0 vpt2 V\n", /* Plus (Add) */
- " currentpoint stroke M\n",
- " hpt neg vpt neg R hpt2 0 V stroke\n",
- " } def\n",
- "/B { stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M\n", /* Box */
- " 0 vpt2 neg V hpt2 0 V 0 vpt2 V\n",
- " hpt2 neg 0 V closepath stroke\n",
- " P } def\n",
- "/C { stroke [] 0 setdash exch hpt sub exch vpt add M\n", /* Cross */
- " hpt2 vpt2 neg V currentpoint stroke M\n",
- " hpt2 neg 0 R hpt2 vpt2 V stroke } def\n",
- "/T { stroke [] 0 setdash 2 copy vpt 1.12 mul add M\n", /* Triangle */
- " hpt neg vpt -1.62 mul V\n",
- " hpt 2 mul 0 V\n",
- " hpt neg vpt 1.62 mul V closepath stroke\n",
- " P } def\n",
- "/S { 2 copy A C} def\n", /* Star */
- NULL
- };
-
- #define NEXTFE_XOFF 50 /* page offset in pts */
- #define NEXTFE_YOFF 50
-
- #define NEXTFE_XMAX 7200
- #define NEXTFE_YMAX 5040
-
- #define NEXTFE_XLAST (NEXTFE_XMAX - 1)
- #define NEXTFE_YLAST (NEXTFE_YMAX - 1)
-
- #define NEXTFE_VTIC (NEXTFE_YMAX/80)
- #define NEXTFE_HTIC (NEXTFE_YMAX/80)
-
- #define NEXTFE_SC (10) /* scale is 1pt = 10 units */
- #define NEXTFE_LW (0.5*NEXTFE_SC) /* linewidth = 0.5 pts */
-
- #define NEXTFE_VCHAR (14*NEXTFE_SC) /* default is 14 point characters */
- #define NEXTFE_HCHAR (14*NEXTFE_SC*6/10)
-
- int NEXTFE_pen_x, NEXTFE_pen_y;
- int NEXTFE_taken;
- int NEXTFE_linetype_last;
- TBOOLEAN NEXTFE_relative_ok;
-
- NEXTFE_options()
- {
- extern struct value *const_express();
- extern double real();
-
- if (!END_OF_COMMAND && isstring(c_token)) {
- quote_str(nextfe_font,c_token);
- c_token++;
- }
-
- if (!END_OF_COMMAND) {
- /* We have font size specified */
- struct value a;
- nextfe_fontsize = (int)real(const_express(&a));
- term_tbl[term].v_char = (unsigned int)(nextfe_fontsize*NEXTFE_SC);
- term_tbl[term].h_char = (unsigned int)(nextfe_fontsize*NEXTFE_SC*6/10);
- }
-
- }
-
-
- NEXTFE_init()
- {
- struct termentry *t = &term_tbl[term];
- int i;
- nextfe_needsReset = TRUE;
-
- NXPrintf(EPSStream,"%%!PS-Adobe-2.0 EPSF-2.0\n");
- NXPrintf(EPSStream,"%%%%Creator: gnuplot\n");
- NXPrintf(EPSStream,"%%%%DocumentFonts: %s\n", nextfe_font);
- NXPrintf(EPSStream,"%%%%BoundingBox: %d %d ", NEXTFE_XOFF,NEXTFE_YOFF);
-
- /*
- * The following calculates the size of the bounding box. If
- * nextfe_halve is TRUE, the actual size of the entire plot,
- * including fonts, is halved.
- */
- NXPrintf(EPSStream,"%d %d\n",
- (int)(xsize * (nextfe_halve? 0.5: 1.0) * (NEXTFE_XMAX) / NEXTFE_SC
- + 0.5 + NEXTFE_XOFF),
- (int)(ysize * (nextfe_halve? 0.5: 1.0) * (NEXTFE_YMAX) / NEXTFE_SC
- + 0.5 + NEXTFE_YOFF));
-
- NXPrintf(EPSStream,"%%%%EndComments\n");
- NXPrintf(EPSStream,"/gnudict 40 dict def\ngnudict begin\n");
- NXPrintf(EPSStream,"/Color %s def\n",nextfe_color ? "true" : "false");
- NXPrintf(EPSStream,"/gnulinewidth %.3f def\n",NEXTFE_LW);
- NXPrintf(EPSStream,"/vshift %d def\n", (int)(t->v_char)/(-3));
- NXPrintf(EPSStream,"/dl {%d mul} def\n",NEXTFE_SC); /* dash length */
- NXPrintf(EPSStream,"/hpt %.1f def\n",NEXTFE_HTIC/2.0);
- NXPrintf(EPSStream,"/vpt %.1f def\n",NEXTFE_VTIC/2.0);
- for ( i=0; NEXTFE_header[i] != NULL; i++)
- NXPrintf(EPSStream,"%s",NEXTFE_header[i]);
- NXPrintf(EPSStream,"end\n");
- NXPrintf(EPSStream,"%%%%EndProlog\n");
- }
-
-
- NEXTFE_graphics()
- {
- struct termentry *t = &term_tbl[term];
- NXPrintf(EPSStream,"gnudict begin\n");
- NXPrintf(EPSStream,"gsave\n");
- NXPrintf(EPSStream,"%d %d translate\n",NEXTFE_XOFF,NEXTFE_YOFF);
-
- /*
- * The following scales the plot. It halves the actual size
- * of the plot if nextfe_halve is TRUE.
- */
- NXPrintf(EPSStream,"%.3f %.3f scale\n", (nextfe_halve? 0.5: 1.0)
- / NEXTFE_SC, (nextfe_halve? 0.5: 1.0) / NEXTFE_SC);
- NXPrintf(EPSStream,"0 setgray\n");
- NXPrintf(EPSStream,"/%s findfont %d ",nextfe_font, (t->v_char) );
- NXPrintf(EPSStream,"scalefont setfont\n");
- NXPrintf(EPSStream,"newpath\n");
- nextfe_path_count = 0;
-
- NEXTFE_relative_ok = FALSE;
- NEXTFE_pen_x = NEXTFE_pen_y = -4000;
- NEXTFE_taken = 0;
- NEXTFE_linetype_last = -1;
-
- }
-
-
- NEXTFE_text()
- {
- nextfe_path_count = 0;
- NXPrintf(EPSStream,"stroke\ngrestore\nend\nshowpage\n");
- }
-
-
- NEXTFE_reset()
- {
- if (nextfe_needsReset) {
- NXPrintf(EPSStream,"%%%%Trailer\n");
- NXFlush(EPSStream);
- nextfe_needsReset = FALSE;
- }
- }
-
-
- NEXTFE_linetype(linetype)
- int linetype;
- {
- char *line = "ba012345678";
-
- linetype = (linetype % 9) + 2;
- NEXTFE_relative_ok = FALSE;
- if (NEXTFE_linetype_last == linetype) return;
- NEXTFE_linetype_last = linetype;
- NXPrintf(EPSStream,"LT%c\n", line[linetype]);
- nextfe_path_count = 0;
- }
-
-
- NEXTFE_move(x,y)
- unsigned int x,y;
- {
- int dx, dy;
- char abso[20],rel[20];
- dx = x - NEXTFE_pen_x;
- dy = y - NEXTFE_pen_y;
- /* can't cancel all null moves--need a move after stroking */
- if (dx==0 && dy==0 && NEXTFE_relative_ok)
- return;
- sprintf(abso, "%d %d M\n", x, y);
- sprintf(rel, "%d %d R\n", dx, dy);
- if (strlen(rel) < strlen(abso) && NEXTFE_relative_ok){
- NXPrintf(EPSStream, "%s",rel);
- NEXTFE_taken++;
- }else
- NXPrintf(EPSStream, "%s",abso);
- NEXTFE_relative_ok = TRUE;
- nextfe_path_count += 1;
- NEXTFE_pen_x = x;
- NEXTFE_pen_y = y;
- }
-
-
- NEXTFE_vector(x,y)
- unsigned int x,y;
- {
- int dx, dy;
- char abso[20],rel[20];
- dx = x - NEXTFE_pen_x;
- dy = y - NEXTFE_pen_y;
- if (dx==0 && dy==0) return;
- sprintf(abso, "%d %d L\n", x, y);
- sprintf(rel, "%d %d V\n", dx, dy);
- if (strlen(rel) < strlen(abso) && NEXTFE_relative_ok){
- NXPrintf (EPSStream, "%s", rel);
- NEXTFE_taken++;
- }else
- NXPrintf (EPSStream, "%s", abso);
- NEXTFE_relative_ok = TRUE;
- nextfe_path_count += 1;
- NEXTFE_pen_x = x;
- NEXTFE_pen_y = y;
- if (nextfe_path_count >= 400) {
- NXPrintf (EPSStream, "currentpoint stroke M\n");
- nextfe_path_count = 0;
- }
- }
-
-
- NEXTFE_put_text(x,y,str)
- unsigned int x, y;
- char *str;
- {
- char ch;
- if (!strlen (str)) return;
- NEXTFE_move(x,y);
- if (nextfe_ang != 0)
- NXPrintf(EPSStream,"currentpoint gsave translate %d rotate 0 0 M\n"
- ,nextfe_ang*90);
- NXPutc(EPSStream, '(');
- ch = *str++;
- while(ch!='\0') {
- if ( (ch=='(') || (ch==')') || (ch=='\\') )
- NXPutc(EPSStream,'\\');
- NXPutc(EPSStream,ch);
- ch = *str++;
- }
- switch(nextfe_justify) {
- case LEFT : NXPrintf(EPSStream,") Lshow\n");
- break;
- case CENTRE : NXPrintf(EPSStream,") Cshow\n");
- break;
- case RIGHT : NXPrintf(EPSStream,") Rshow\n");
- break;
- }
- if (nextfe_ang != 0)
- NXPrintf(EPSStream,"grestore\n");
- nextfe_path_count = 0;
- NEXTFE_relative_ok = FALSE;
- }
-
- int NEXTFE_text_angle(ang)
- int ang;
- {
- nextfe_ang=ang;
- return TRUE;
- }
-
- int NEXTFE_justify_text(mode)
- enum JUSTIFY mode;
- {
- nextfe_justify=mode;
- return TRUE;
- }
-
- /* postscript point routines */
- NEXTFE_point(x,y,number)
- int x,y;
- int number;
- {
- char *point = "PDABCTS";
- number %= POINT_TYPES;
- if (number < -1)
- number = -1; /* negative types are all 'dot' */
- NXPrintf(EPSStream,"%d %d %c\n", x, y, point[number+1]);
-
- NEXTFE_relative_ok = 0;
- nextfe_path_count = 0;
- }
-